import store from "@/store";
import request from "@/utils/request";

// 获取用户ID的公共函数
const getUserId = () => store.getters["system/userId"];
const getHehunUserId = () => store.getters["hehun/hehunUserId"];

// 获取用户支付次数
export function getUserPayCount() {
  return request({
    url: "/v1/aiml/userPayCount",
    method: "get",
  });
}
// 初始提交 |返回用户id
export function putUserInfo(data) {
  return request({
    url: "/v1/aiml/create",
    method: "post",
    data,
  });
}

// 获取用户信息 |返回用户信息
export function getUserInfo() {
  const userId = getUserId();
  return request({
    url: "/v1/aiml/create/result",
    method: "get",
    params: { userId },
  });
}
// 获取婚姻八字结果
export function getMarryInfo() {
  const userId = getUserId();
  return request({
    url: "/v1/aiml/userBaziHunYin",
    method: "get",
    params: { userId },
  });
}
// 获取八字健康、事业等结果
export function getOtherInfo() {
  const userId = getUserId();
  return request({
    url: "/v1/aiml/userBazi",
    method: "get",
    params: { userId },
  });
}

// 合婚提交
export function puthehunUserInfo(data) {
  return request({
    url: "/v1/aiml/hehun",
    method: "post",
    data,
  });
}
// 合婚用户信息
export function getHehunUserInfo() {
  const hehunId = getHehunUserId();
  return request({
    url: "/v1/aiml/heHunUserInfo",
    method: "get",
    params: { hehunId },
  });
}
// 合婚结果
export function getHehunResultInfo() {
  const hehunId = getHehunUserId();
  const userId = getUserId();
  return request({
    url: "/v1/aiml/userBaziHeHun",
    method: "get",
    params: { hehunId,userId },
  });
}

// 埋点上报
export function reportEvent(data) {
  const userId = getUserId();
  return request({
    url: "/v1/aiml/report",
    method: "post",
    data: {
      userId,
      ...data,
      ipAddr: "192.168.0.1",
      clickId: "广告相关",
      sourceForm: "广告相关",
      planId: "广告相关",
    },
  });
}

// 订单创建，返回支付链接
export function createOrder(data) {
  const userId = getUserId();
  return request({
    url: "/v1/wxPay/marketing ",
    method: "post",
    data: { userId, goodsId: data.goodsId, payAmount: data.payAmount },
  });
}
/**
 * {
        "orderNo": "订单号",
        "payUrl": "支付链接"
    }
 */

//查看订单状态
export function queryOrder(value) {
  return request({
    url: "/v1/wxPay/queryByOrderNo",
    method: "get",
    params: { orderNo: value },
  });
}

// 绑定手机号

export function bindUserPhone(userPhone) {
  const userId = getUserId();
  return request({
    url: "/v1/wxPay/bindUserPhone",
    method: "get",
    params: { userId, userPhone },
  });
}

// 通过手机号查询数据
// /v1/aiml/findResultByUserPhone
export function findResultByUserPhone(userPhone) {
  return request({
    url: "/v1/aiml/findResultByUserPhone",
    method: "get",
    params: { userPhone },
  });
}
